/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Fenetre;




import Fenetre.BoutonListener.BouttonListenerCreer;
import Fenetre.BoutonListener.ButtonListenerAjouterDate;

import java.awt.FlowLayout;
import java.util.ArrayList;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.joda.time.DateTime;

/**
 *
 * @author gerard.dl02
 */
public class FenetreCreer extends JFrame{
    

  private JCheckBox siteAngers;
  private JCheckBox siteNantes;
  private JCheckBox siteRennes;
  private  JTextField raisonSociale;
  private  JTextField adresse;
  private JTextField codePostal;
  private  JTextField ville;
  private  JTextField nomSignataire;
  private   JTextField nomIntervenant;
  private  JTextField telIntervenant;
  private  JTextField mailIntervenant;
  private ArrayList<DateTime> dates;
  private JPanel panelListeDates;
  private JList listeDates;
  private JTextField jour;
  private JTextField mois;
private JTextField annee;
private JRadioButton journee;
private JRadioButton matinee;
private JRadioButton apresmidi;
  private  JTextField designation;
  private  ComboBoxSessions session;
  private  JTextField PrixUnitaire;
  private   JCheckBox matin;
  private  JCheckBox apremMidi;
  private  JCheckBox cheque;
  private  JCheckBox virement;
  private   JTextField observation;
  private  JTextField delMin;
  private  JTextField delMax;
  private  JTextField objectifIntervention;
    
    
    public FenetreCreer(){
        
 
        
      //------------------------------------------------------------------------
        //Création la base de la fenêtre 
        
        this.setSize(1200,800);
        this.setTitle("Créer");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.dates = new ArrayList<>();
        
        
        this.setContentPane(this.creationPanel());
        this.panelListeDates();
        this.setVisible(true); // Rend la fenêtre visible
        
    }
    
   
    private JPanel reglement(){
        
        this.delMin = new JTextField(2);
        this.delMax = new JTextField(2);
        this.cheque = new JCheckBox("Chèque");
        this.cheque.setSelected(true);
        this.virement = new JCheckBox("Virement");
        this.observation = new JTextField(20);
        
        
        ButtonGroup groupeCheckBox = new ButtonGroup();
        
        JLabel labelDelai = new JLabel("Délai de ");
        JLabel labelA = new JLabel(" à ");
        JLabel labelJours  = new JLabel(" Jours.");
        JLabel labelMoyensReglement = new JLabel("Moyens de règlement: ");
        JLabel labelObservations = new JLabel("Observations : ");
        
        
        JPanel  panelReglement = new JPanel();
        JPanel panelDelai = new JPanel();
        JPanel panelObservation = new JPanel();
        JPanel panReglement = new JPanel();
        
        groupeCheckBox.add(cheque);
        groupeCheckBox.add(virement);
        
        panelObservation.add(labelObservations);
        panelObservation.add(observation);
        
        panelReglement.add(labelMoyensReglement);
        panelReglement.add(cheque);
        panelReglement.add(virement);
        
        panelDelai.add(labelDelai);
        panelDelai.add(delMin);
        panelDelai.add(labelA);
        panelDelai.add(delMax);
        panelDelai.add(labelJours);
        
        
        panReglement.add(panelDelai);
        panReglement.add(panelReglement);
        panReglement.add(panelObservation);
        

        return panReglement;
    }
    
    
    private JPanel pedagogie(){
        
        JLabel labelInformations = new JLabel("Informations pédagogiques : ");
        this.objectifIntervention = new JTextField(20);
        
        JPanel panelPedagogie = new JPanel();
        
        panelPedagogie.add(labelInformations);
        panelPedagogie.add(objectifIntervention);
        
        return panelPedagogie;
        
    }
    
    
    
    private JPanel horaireDesCours(){
        
       JLabel labelHoraires = new JLabel("Horaires : "); 
       this.matin = new JCheckBox("09H00 à 12H30 / 13H30 à 17H");
       this.matin.setSelected(true);
       this.apremMidi = new JCheckBox("09H00 à 12H00 / 13H30 à 17H");
       
       JPanel panelHoraireDesCours = new JPanel();
       
       panelHoraireDesCours.add(labelHoraires);
        panelHoraireDesCours.add(matin);
        panelHoraireDesCours.add(apremMidi);
        
        return panelHoraireDesCours;
        
    }

    private JPanel commande(){
        
        
        this.jour = new JTextField(2);
        this.mois = new JTextField(2);
        this.annee = new JTextField(4);
        this.journee = new JRadioButton("Journée");
        this.journee.setSelected(true);
        this.matinee = new JRadioButton("Matinée");
        this.apresmidi = new JRadioButton("Après-midi");
        this.PrixUnitaire = new JTextField(5);
        this.designation = new JTextField(8);
        try {
        this.session = new ComboBoxSessions();
        } catch (Exception e){
            new FenetreException(e);
        }
        
        JButton boutonDate = new JButton("Ajouter à la liste");
        boutonDate.addActionListener(new ButtonListenerAjouterDate(this));
     
        JPanel panelDate = new JPanel();
        this.panelListeDates = new JPanel();
        JPanel panelTextField = new JPanel();
        JPanel panelCommande = new JPanel();
        

        
        panelTextField.add(new JLabel("Designation : "));
        panelTextField.add(designation);
        panelTextField.add(new JLabel("Session : "));
        panelTextField.add(session);
        panelTextField.add(new JLabel("Prix unitaire H.T. : "));
        panelTextField.add(PrixUnitaire);
       
        
        panelDate.add(new JLabel("Date"));
        panelDate.add(jour);
        panelDate.add(new JLabel("/"));
        panelDate.add(mois);
        panelDate.add(new JLabel("/"));
        panelDate.add(annee);
        panelDate.add(journee);
        panelDate.add(matinee);
        panelDate.add(apresmidi);
        panelDate.add(boutonDate);
        
        panelListeDates.add(new JLabel("Dates des cours : "));
 
        
        panelCommande.add(panelDate);
        panelCommande.add(this.panelListeDates);
        panelCommande.add(panelTextField);
        
        return panelCommande;
    }
    
    private JPanel sites(){
        
        this.siteAngers = new JCheckBox("Angers");
        this.siteNantes = new JCheckBox("Nantes");
        this.siteRennes = new JCheckBox("Rennes");
        ButtonGroup sites = new ButtonGroup();
        sites.add(siteAngers);
        sites.add(siteNantes);
        sites.add(siteRennes);
        
        JPanel panelSites = new JPanel();
        panelSites.add(new JLabel("Site concerné : "));
        panelSites.add(siteAngers);
        siteAngers.setSelected(true);
        panelSites.add(siteNantes);
        panelSites.add(siteRennes);
        
        return (panelSites);
    }
    
     private JPanel coordonnéePrestataire(){
        
        this.raisonSociale = new JTextField(10);
        this.adresse = new JTextField(10);
        this.codePostal = new JTextField(10);
        this.ville = new JTextField(10);
        this.nomSignataire = new JTextField(10);
        
        JLabel labelRaisonSocial = new JLabel("Raison sociale");
        JLabel labelAdresse = new JLabel("Adresse");
        JLabel labelCodePostal = new JLabel("Code postal");
        JLabel labelNomSignataire = new JLabel("Nom du signataire");
        JLabel labelVille = new JLabel("Ville");
        
        JPanel panelRaisonSocial = new JPanel();
        JPanel panelSite = new JPanel();
        JPanel panelAdresse = new JPanel();
        JPanel panelCodePostal = new JPanel();
        JPanel panelNomSignataire = new JPanel();
        JPanel panelVille = new JPanel();
         
        JPanel panelCoordonnée = new JPanel(new FlowLayout());
        
        panelRaisonSocial.add(labelRaisonSocial);
        panelRaisonSocial.add(raisonSociale);
        
        panelAdresse.add(labelAdresse);
        panelAdresse.add(adresse);
        
        panelCodePostal.add(labelCodePostal);
        panelCodePostal.add(codePostal);
        
        panelNomSignataire.add(labelNomSignataire);
        panelNomSignataire.add(nomSignataire);
        
        panelVille.add(labelVille);
        panelVille.add(ville);
        
        panelCoordonnée.add(panelSite);
        panelCoordonnée.add(panelRaisonSocial);
        panelCoordonnée.add(panelAdresse);
        panelCoordonnée.add(panelCodePostal);
        panelCoordonnée.add(panelVille);
        panelCoordonnée.add(panelNomSignataire);
        
        return panelCoordonnée;
        
    }
     private JPanel coordonneesIntervenant() {
         
         this.nomIntervenant = new JTextField(10);
        this.telIntervenant = new JTextField(10);
        this.mailIntervenant= new JTextField(10);
        
        JPanel panelIntervenant = new JPanel();
        panelIntervenant.add(new JLabel("Nom de l'intervenant : "));
        panelIntervenant.add(nomIntervenant);
        panelIntervenant.add(new JLabel("Tel : "));
        panelIntervenant.add(telIntervenant);
        panelIntervenant.add(new JLabel("Email : "));
        panelIntervenant.add(mailIntervenant);
        
        return(panelIntervenant);
     }
    
    private JPanel createBouttonValider(){
        
        JButton valider = new JButton("Valider");
        JPanel panelValider = new JPanel();
        JPanel contentPaneValider = new JPanel();
        
        panelValider.add(valider);
        contentPaneValider.add(panelValider);
        valider.addActionListener(new BouttonListenerCreer(this));
        
        
        return contentPaneValider;
        
    }    
    
    private JPanel creationPanel(){
        
        JPanel panel1 = new JPanel();
        JPanel panel2 = new JPanel();
        panel2.setLayout(new BoxLayout(panel2,BoxLayout.PAGE_AXIS));

        panel1.add(new MenuBar());
        panel2.add(this.sites());
        panel2.add(this.coordonnéePrestataire());
        panel2.add(this.coordonneesIntervenant());
        panel2.add(this.commande());
        panel2.add(this.horaireDesCours());
        panel2.add(this.pedagogie());
        panel2.add(this.reglement());
        panel2.add(this.createBouttonValider());
        
        
        JPanel panelfinal = new JPanel();
        panelfinal.setLayout(new BoxLayout(panelfinal,BoxLayout.PAGE_AXIS));
        panelfinal.add(panel1);
        panelfinal.add(panel2);
        
        return panelfinal;
        
        
    }
    
    public void panelListeDates(){
        
        String tabDates[] = new String[this.dates.size()];
        int nb = 0;
        for (DateTime date : this.dates){
            tabDates[nb] = date.getDayOfMonth()+"/"+date.getMonthOfYear()+"/"+date.getYear();
            nb++;
        }
        JList liste = new JList(tabDates);
        liste.setVisibleRowCount(5);
        if (this.listeDates != null) {
        this.panelListeDates.remove(this.listeDates);
        }
        this.listeDates = liste;
        this.panelListeDates.add(liste);
        this.revalidate();
        this.repaint();
    }

    public JTextField getRaisonSociale() {
        return raisonSociale;
    }

    public JTextField getAdresse() {
        return adresse;
    }

    public JTextField getCodePostal() {
        return codePostal;
    }

    public JTextField getVille() {
        return ville;
    }

    public JTextField getNomSignataire() {
        return nomSignataire;
    }

    public JTextField getNomIntervenant() {
        return nomIntervenant;
    }

    public JTextField getTelIntervenant() {
        return telIntervenant;
    }

    public JTextField getMailIntervenant() {
        return mailIntervenant;
    }

    public JTextField getDesignation() {
        return designation;
    }

    public ComboBoxSessions getSession() {
        return session;
    }

    public JTextField getPrixUnitaire() {
        return PrixUnitaire;
    }

    public JTextField getAnnee() {
        return annee;
    }

    public JTextField getMois() {
        return mois;
    }

    public JTextField getour() {
        return jour;
    }

    public JCheckBox getSiteAngers() {
        return siteAngers;
    }

    public JCheckBox getSiteNantes() {
        return siteNantes;
    }

    public JCheckBox getSiteRennes() {
        return siteRennes;
    }

    public JCheckBox getMatin() {
        return matin;
    }

    public JCheckBox getApremMidi() {
        return apremMidi;
    }

    public JCheckBox getCheque() {
        return cheque;
    }

    public JCheckBox getVirement() {
        return virement;
    }

    public JTextField getObservation() {
        return observation;
    }

    public JTextField getDelMin() {
        return delMin;
    }

    public JTextField getDelMax() {
        return delMax;
    }

    public JTextField getObjectifIntervention() {
        return objectifIntervention;
    }

    public JTextField getDelaiMin() {
        return delMin;
    }

    public JTextField getDelaiMax() {
        return delMax;
    }

    public ArrayList<DateTime> getDates() {
        return dates;
    }

    public JTextField getJour() {
        return jour;
    }

    public JRadioButton getJournee() {
        return journee;
    }

    public JRadioButton getMatinee() {
        return matinee;
    }

    public JRadioButton getApresmidi() {
        return apresmidi;
    }
    
    
    
    
    
}
